from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles
from fastapi.middleware.cors import CORSMiddleware

from app.config import settings
from app.routers.ifc_router import router as ifc_router
from app.routers.platform_router import router as platform_router
from app.routers.ai_rule_router import router as ai_rule_router
from app.exception_handlers import add_exception_handlers

app = FastAPI(
    title="智能BIM合规审查平台",
    description="基于AI的IFC文件合规性分析与审查平台",
    version="2.0.0"
)

# 配置CORS
app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

# 添加异常处理器
add_exception_handlers(app)

# 包含路由
app.include_router(ifc_router, prefix=settings.API_PREFIX)
app.include_router(platform_router, prefix=settings.API_PREFIX)
app.include_router(ai_rule_router, prefix=settings.API_PREFIX)

# 挂载静态文件
app.mount("/static", StaticFiles(directory="static"), name="static")
app.mount("/smart", StaticFiles(directory="templates/smart_features"), name="smart")

@app.get("/")
async def root():
    return {
        "message": "智能BIM合规审查平台",
        "version": "2.0.0",
        "features": [
            "IFC文件上传与转换",
            "AI智能合规分析",
            "实时进度跟踪",
            "详细结果展示"
        ],
        "docs": "/docs",
        "frontend": "/static/index.html"
    }

@app.get("/health")
async def health_check():
    """健康检查端点"""
    return {"status": "healthy", "service": "bim-compliance-platform"}